﻿using System;
using System.Collections.Generic;
using System.Text;

namespace NGE.MH.GUI
{
    class Buy : Panelbox
    {
        public Buy(Game g)
            : base(g)
        {
            OnPanelboxOpen += new GUIEvent(OnInit);
            desp = new Textbox();
            desp.Text = "";
            desp.Location = new Microsoft.DirectX.Vector3(320, 20, 0);
            Elements.Add(desp);
        }

        Textbox desp;
        List<Prop> props;

        public void OnInit(object sender, object arg)
        {
            props = (List<Prop>)arg;
            Buttonboxes.Clear();

            int i = 0;
            foreach (Prop prop in props)
            {
                Buttonbox bb = new Buttonbox();
                bb.Text = prop.Name;
                bb.Location = new Microsoft.DirectX.Vector3(20, 20 + i * 20, 0);
                bb.OnButtonboxEvent += new GUIEvent(bb_OnButtonboxEvent);
                Buttonboxes.Add(bb);
                i++;
            }
        }

        void bb_OnButtonboxEvent(object sender, object arg)
        {
            Buttonbox me = (Buttonbox)sender;
            int i = me.StopIndex;
            if ((ButtonboxState)arg == ButtonboxState.Down)
            {
                game.Script.AS(props[i].Script);
            }
            else if ((ButtonboxState)arg == ButtonboxState.Focus)
            {
                desp.Text = props[i].Description;
            }
        }

        protected override void OnKeyboardEventCode(object sender, int key, KeyboardState ks)
        {
            base.OnKeyboardEventCode(sender, key, ks);

        }
    }
}
